package operation;

import book.Book;
import book.BookLIst;

import java.util.Scanner;

public class AddBook implements Ioperation{
    public void work(BookLIst books){
        System.out.println("增加图书");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入书籍名称：");
        String bookName = sc.nextLine();
        System.out.println("请输入书籍作者：");
        String author = sc.nextLine();
        System.out.println("请输入书籍价格");
        int price = sc.nextInt();
        sc.nextLine();
        System.out.println("请输入书籍类型：");
        String type = sc.nextLine();
        Book book = new Book(bookName, author, price, type);
        int currentSize = books.getUsedSize();
        for(int i = 0; i < currentSize; i++){
            Book temp = books.getBook(i);
            if(temp.getName().equals(bookName)){
                System.out.println("有这本书，可以不上架！！！");
                return;
            }
        }
       books.setBookList(currentSize,book);
        books.setUsedSize(currentSize + 1);
        System.out.println("已成功上架");
    }
}
